package com.wxh.multithread;

import java.util.concurrent.*;

/**
 * @ClassName: TestCallable
 * @Description: 测试Callable
 * @Author wxh
 * @Date: 2021/12/24 16:16
 * @Version V1.0.0
 * @Since 1.8
 */
public class TestCallable implements Callable<Boolean> {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        TestCallable t1 = new TestCallable();
        TestCallable t2 = new TestCallable();
        TestCallable t3 = new TestCallable();

        // 创建执行服务--线程池创建三个线程
        ExecutorService executorService = Executors.newFixedThreadPool(3);
        // 提交执行
        Future<Boolean> f1 = executorService.submit(t1);
        Future<Boolean> f2 = executorService.submit(t2);
        Future<Boolean> f3 = executorService.submit(t3);
        // 获取结果
        boolean rs1 = f1.get();
        boolean rs2 = f2.get();
        boolean rs3 = f3.get();
        // 关闭服务
        executorService.shutdownNow();
    }

    @Override
    public Boolean call() throws Exception {
        System.out.println("调用后，返回结果");
        return null;
    }


}
